<template>
  <div class="cus__steps">
    <ul class="cus__steps__header">
      <li
        v-for="(step, idx) in stepList" 
        :key="step" 
        :class="{ 'is__current': active === idx, 'is__complete': finish >= idx }"
        :data-index="idx + 1"
        @click="$emit('active-change', idx)"
      >
        <i class="el-icon-check" />
        <span>{{ step }}</span>
      </li>
    </ul>
    <ul class="cus__steps__content">
      <slot />  
    </ul>
  </div>
</template>

<script lang="ts">
import { ref, Ref, provide } from 'vue';
export default {
  name: 'cus-steps',
  props: {
    active: {
      type: Number,
      default: 0
    },
    finish: {
      type: Number,
      default: -1
    }
  },
  setup(props, { emit }) {
    let stepList: Ref<string[]> = ref([]);

    provide('set_pane', (step) => {stepList.value.push(step); console.log(step)});

    return { stepList }
  }
}

export type SetPaneCallback = (pane: string) => void;

</script>

<style lang="scss" scoped>
.cus__steps {
  padding: 15px 45px;
  margin-bottom: 20px;
  background: #fff;
  border-radius: 6px;
  .cus__steps__header {
    height: 40px;
    display: flex;
    overflow: hidden;
    li {
      flex: 1;
      color: #666;
      font-size: 18px;
      line-height: 40px;
      text-align: center;
      background: #F0F2F5;
      position: relative;
      cursor: pointer;
      &.is__disabled {
        pointer-events: none;
      }
      &.is__complete {
        color: #fff;
        background: #99D6D2;
        i {
          display: inline-block;
        }
        &::before {
          display: none;
        }
      }
      &.is__current {
        color: #fff;
        background: #63C7C2;
      }
      &.is__complete, 
      &.is__current {
        &::before {
          border-color: #fff;
        }
      }
      &:not(:first-child) {
        margin-left: -10px;
      }
      &:not(:last-child)::after {
        content: '';
        display: block;
        width: 32px;
        height: 30px;
        border-top: solid 10px #fff;
        border-right: solid 10px #fff;
        background: inherit;
        position: absolute;
        top: 0;
        right: 0;
        z-index: 2;
        margin-right: -10px;
        border-radius: 6px;
        transform: rotateZ(45deg);
      }
      &:first-child {
        border-top-left-radius: 6px;
        border-bottom-left-radius: 6px;
      }
      &:last-child {
        border-top-right-radius: 6px;
        border-bottom-right-radius: 6px;
      }
      &::before {
        content: attr(data-index);
        display: inline-block;
        width: 26px;
        height: 26px;
        margin-top: 7px;
        margin-right: 10px;
        line-height: 22px;
        color: inherit;
        font-size: 14px;
        text-align: center;
        border: solid 2px #666;
        border-radius: 50%;
        box-sizing: border-box;
        vertical-align: top;
      }
      i {
        display: none;
        width: 26px;
        height: 26px;
        color: #99D6D2;
        line-height: 26px;
        text-align: center;
        font-weight: bold;
        background: #fff;
        vertical-align: top;
        margin: 7px 10px 0 0;
        border-radius: 50%;
      }
    }
  }
}
</style>